// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#pragma once
#include <pollux/vector/complex_vector.h>
#include <pollux/vector/vector_stream.h>

namespace kumo::pollux::serializer::spark {
    class UnsafeRowVectorSerde : public VectorSerde {
    public:
        UnsafeRowVectorSerde() : VectorSerde(VectorSerde::Kind::kUnsafeRow) {
        }

        void estimateSerializedSize(
            const row::UnsafeRowFast *unsafeRow,
            const melon::Range<const vector_size_t *> &rows,
            vector_size_t **sizes) override;

        // This method is not used in production code. It is only used to
        // support round-trip tests for deserialization.
        std::unique_ptr<IterativeVectorSerializer> createIterativeSerializer(
            RowTypePtr type,
            int32_t numRows,
            StreamArena *streamArena,
            const Options *options) override;

        // This method is used when reading data from the exchange.
        void deserialize(
            ByteInputStream *source,
            pollux::memory::MemoryPool *pool,
            RowTypePtr type,
            RowVectorPtr *result,
            const Options *options) override;

        static void registerVectorSerde();

        static void registerNamedVectorSerde();
    };
} // namespace kumo::pollux::serializer::spark
